package com.example.mobilesafe1221.home;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.example.mobilesafe1221.MainActivity;
import com.example.mobilesafe1221.R;

import java.util.Timer;
import java.util.TimerTask;

public class SplashActivity extends AppCompatActivity {
    private TextView skip ;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        //初始话控件的方法
        initView();  //调用 方法
        setListener();
    }
    private void setListener() {
        skip.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent1=new Intent(SplashActivity.this, MainActivity.class);
                startActivity(intent1);
                finish();
            }
        });
    }

    private void initView() {
        TextView tv_version=findViewById(R.id.tv_version);//获取布局文件中的控件
        skip =findViewById(R.id.skip);
        //自动加上类型与变量
        PackageInfo packageInfo = null;
        try {
            packageInfo = getPackageManager().getPackageInfo(getPackageName(),0);
            tv_version.setText("当前版本号为:"+packageInfo.versionName);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            tv_version.setText("当前版本为：X");
        }
        /*AIT+SHift+L   自动加上类型与变量
         * aIT +shift +Z   try--catch   快捷*/
        Timer timer=new Timer() ; //自定义时间跳转方法   new 调用Time ()构造方法
        TimerTask timerTask = new TimerTask(){
            @Override
            public void run() {
                //intent 类之间进行交互
                Intent intent = new Intent(SplashActivity.this, Homeactivity.class);
                startActivity(intent);

                SplashActivity.this.finish();

            }
        };
        timer.schedule(timerTask,2000);  //执行

    }
}
